Trace and Break

Scheme provides procedures that allow you to trace the execution of a program and set breakpoints in the program. A procedure can be traced on entry or on exit. In addition, a breakpoint can be set when the procedure is entered or exited. When the entry of a program is traced, the arguments passed to it are shown at each entry. When the exit of a program is traced the arguments passed and the result returned are shown at each exit. Here is an example. The indicators preceding the user's input show the level and REP loop information that appears in the mode line at each point. $\Longrightarrow$
$\Longrightarrow$ unspecified error `=̀13`


          [1 REP] (define (fact n)           (cond ((zero? n) 1)                 (else (* n (fact (-1+ n))))))FACT 

[1 REP] (trace-entry fact)

[1 REP] (trace-exit fact)

[1 REP] (fact 3) Entering <#<COMPOUND-PROCEDURE FACT> 3> Entering <#<COMPOUND-PROCEDURE FACT> 2> Entering <#<COMPOUND-PROCEDURE FACT> 1> Entering <#<COMPOUND-PROCEDURE FACT> 0> 1 <== <#<COMPOUND-PROCEDURE FACT> 0> 1 <== <#<COMPOUND-PROCEDURE FACT> 1> 2 <== <#<COMPOUND-PROCEDURE FACT> 2> 6 <== <#<COMPOUND-PROCEDURE FACT> 3> 6

[1 REP] (untrace fact)

[1 REP] (fact 3) 6

[1 REP] (break-exit fact)

[1 REP] (fact 2) 1 <== <#<COMPOUND-PROCEDURE FACT> 0> Breakpoint on exit

[2 Break] (*args*) (0)

[2 Break] (*result*) 1

[2 Break] (proceed -1) -1 <== <#<COMPOUND-PROCEDURE FACT> 1> Breakpoint! Level: 2

[2 Break] (proceed) -2 <== <#<COMPOUND-PROCEDURE FACT> 2> Breakpoint on exit

[2 Break] (proceed) -2

During the breakpoint inserted by ndexfile(index-entry "break-exit" "tt" aux )break-exit, the procedures ndexfile(index-entry "*proc*" "tt" aux )*proc*, ndexfile(index-entry "*args*" "tt" aux )*args*, and ndexfile(index-entry "*result*" "tt" aux )*result* can be called to see the ``broken'' procedure, the values of the arguments, and the computed result (available only during an exit break), respectively. Type (proceed) to proceed from the breakpoint and return the value shown by (*result*), or type (proceed expression) to return the value of expression. In the above example, we made (fact 0) return -1 instead of 1.